local hx__jianmie = fk.CreateSkill {
  name = "hx__jianmie",
}

hx__jianmie:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hx__jianmie.name) and player:usedSkillTimes(hx__jianmie.name, Player.HistoryRound) < 2 then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:loseHp(player, 1, hx__jianmie.name)
      player:drawCards(2, hx__jianmie.name, nil,"@@hx__jianmie-inhand")
    end
  end,
})
hx__jianmie:addEffect(fk.HpChanged, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hx__jianmie.name) and player:usedSkillTimes(hx__jianmie.name, Player.HistoryRound) < 2 then
      return data.reason == "damage" and data.shield_lost > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      local tos = room:askToChoosePlayers(player, {
        targets = room:getAlivePlayers(),
        min_num = 1,
        max_num = 1,
        prompt = "请选择一名角色令其判定，若结果为：黑色，你对该角色造成1雷电伤害；红色，你弃置该角色至多两张手牌",
        skill_name = hx__jianmie.name,
      })
      local to = tos[1]
      local judge = {
        who = to,
        reason = hx__jianmie.name,
        pattern = ".|.",
      }
      room:judge(judge)
      if judge.card.color == Card.Black then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = hx__jianmie.name,
        }
      elseif judge.card.color == Card.Red then
        if #to:getCardIds(Player.Hand) == 0 then return end
        local card = room:askToChooseCards(player, {
          target = to,
          min = 1,
          max = 2,
          flag = "h",
          skill_name = hx__jianmie.name,
        })
        room:throwCard(card, hx__jianmie.name, to, player)
      end
  end,
})

hx__jianmie:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__jianmie.name) and data.card.trueName == "slash" and data.card:getMark("@@hx__jianmie-inhand") > 0
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = data.disresponsiveList or {}
    for _, p in ipairs(player.room.alive_players) do
      table.insertIfNeed(data.disresponsiveList, p)
    end
  end,
})

return hx__jianmie